<?php

namespace admin\widgets;

use common\models\User;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Url;

class MemberActionWidget extends Widget {

    /**
     * @var User
     */
    public $model;

    public function run() {
        $buttons = [];

        $name = $this->model->getIsTop() ? '取消推荐APP' : '推荐到APP';
        $url = Url::to(['member/top', 'id' => $this->model->id]);
        $buttons[] = Html::button($name, ['class' => 'get btn', 'href' => $url]);

        if ($this->model->getIsChecking()) {
            $url = Url::to(['member/approve', 'id' => $this->model->id]);

            $options = ['class' => 'get btn update', 'href' => $url];
            $buttons[] = Html::button('通过审核', $options);

            Html::addCssClass($options, 'danger');
            $options['href'] = Url::to(['member/reject', 'id' => $this->model->id]);
            $buttons[] = Html::button('审核不通过', $options);
        }
        return Html::tag('div', implode('', $buttons), ['class' => 'box btn-action']);
    }
}